package com.example.system.controller;

import com.example.common.core.constants.HttpConstants;
import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.common.core.domain.vo.LoginUserVO;
import com.example.system.domain.sysuser.dto.LoginDTO;
import com.example.system.domain.sysuser.dto.SysUserQueryDTO;
import com.example.system.domain.sysuser.dto.SysUserSaveDTO;
import com.example.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;

    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    // 查看管理员列表
    @GetMapping("/list")
    public TableDataInfo list(SysUserQueryDTO sysUserQueryDTO){
        return getTableDataInfo(sysUserService.list(sysUserQueryDTO));
    }

    @PostMapping("/login")
    public R<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }
    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }
    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(sysUserService.logout(token));
    }
}
